﻿using System;
using ProjectDanmaku.Broadcast;
using UnityEngine;

namespace ProjectDanmaku.Effect
{
    [RequireComponent(typeof(Animator))]
    public class Level0BackgroundEffect : MonoBehaviour
    {
        private Animator _animator;

        private void Awake()
        {
            _animator = GetComponent<Animator>();
        }

        private void OnEnable()
        {
            BroadcastServer.Instance.ListenChannel(CommonChannel.BackgroundEffectChannel, (info) =>
            {
                _animator.ResetTrigger("Flash");
                _animator.SetTrigger("Flash");
            });
        }

        private void OnDisable()
        {
            BroadcastServer.Instance.StopListeningAllChannelsForObject(this);
        }
    }
}